<template>
	<view class="wrap">
		<u-form :model="model" :rules="rules" ref="uForm">
			<u-form-item label-width="350" :label-position="labelPosition" label="溶解气油比" prop="dissolvedGasOilRatio">
				<u-input :border="border" placeholder="请输入溶解气油比" v-model="model.dissolvedGasOilRatio" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350" :label-position="labelPosition" label="充满系数" prop="fillFactor">
				<u-input :border="border" placeholder="请输入充满系数" v-model="model.fillFactor" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350" :label-position="labelPosition" label="含水率(%)" prop="waterContent">
				<u-input :border="border" placeholder="请输入含水率" v-model="model.waterContent" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350" :label-position="labelPosition" label="天然气溶解系数" prop="gasDissolutionFactor">
				<u-input :border="border" placeholder="请输入天然气溶解系数" v-model="model.gasDissolutionFactor" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350" :label-position="labelPosition" label="原油密度(g/cm³)" prop="oilDensity">
				<u-input :border="border" placeholder="请输入原油密度" v-model="model.oilDensity" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350" :label-position="labelPosition" label="地层水密度(g/cm³)" prop="formationWaterDensity">
				<u-input :border="border" placeholder="请输入地层水密度" v-model="model.formationWaterDensity" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350" :label-position="labelPosition" label="油层中部深度(m)" prop="midDepth">
				<u-input :border="border" placeholder="请输入油层中部深度" v-model="model.midDepth" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350" :label-position="labelPosition" label="泵挂深度(m)" prop="pumpDepth">
				<u-input :border="border" placeholder="请输入泵挂深度" v-model="model.pumpDepth" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350" :label-position="labelPosition" label="合理沉没度(m)" prop="reasonableSubmergence">
				<u-input :border="border" placeholder="请输入合理沉没度" v-model="model.reasonableSubmergence" type="digit"></u-input>
			</u-form-item>
		</u-form>

		<u-button type="primary" @click="submit">计算</u-button>

		<view class="u-config-wrap">
			<view class="u-config-item">
				<view class="u-item-title">计算结果</view>
				<u-form-item style="font-size: 22px;" :leftIconStyle="{color: '#888', fontSize: '32rpx'}" label-width="300"
					:label-position="labelPosition" label="合理井底流压" prop="bottomHolePressure">
					<span v-if="model.bottomHolePressure"> {{model.bottomHolePressure}} MPa </span>
				</u-form-item>
			</view>
			<view class="u-config-item">
				<view class="u-item-title">计算公式</view>
				<view class="u-item-desc">合理井底流压 = 抽油泵泵口压力 + 井筒液柱压力</view>
				<view class="u-item-desc">抽油泵泵口压力 = 溶解气油比 /((1∕〖充满系数 - 1〗)/(1 - 含水率)+ 天然气溶解系数)</view>
				<view class="u-item-desc">井筒液柱压力 = 0.01× 混合物密度 ×(油层中部深度 - 泵挂深度 + 合理沉没度)</view>
				<view class="u-item-desc">混合液密度 = 原油密度 × (1 - 含水)+ 含水 × 地层水密度</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				model: {
					dissolvedGasOilRatio: '',
					fillFactor: '',
					waterContent: '',
					gasDissolutionFactor: '',
					oilDensity: '',
					formationWaterDensity: '',
					midDepth: '',
					pumpDepth: '',
					reasonableSubmergence: '',
					bottomHolePressure: ''
				},
				rules: {
					dissolvedGasOilRatio: [{
						required: true,
						message: '请输入溶解气油比',
						trigger: 'blur'
					}],
					fillFactor: [{
						required: true,
						message: '请输入充满系数',
						trigger: 'blur'
					}],
					waterContent: [{
						required: true,
						message: '请输入含水率',
						trigger: 'blur'
					}],
					gasDissolutionFactor: [{
						required: true,
						message: '请输入天然气溶解系数',
						trigger: 'blur'
					}],
					oilDensity: [{
						required: true,
						message: '请输入原油密度',
						trigger: 'blur'
					}],
					formationWaterDensity: [{
						required: true,
						message: '请输入地层水密度',
						trigger: 'blur'
					}],
					midDepth: [{
						required: true,
						message: '请输入油层中部深度',
						trigger: 'blur'
					}],
					pumpDepth: [{
						required: true,
						message: '请输入泵挂深度',
						trigger: 'blur'
					}],
					reasonableSubmergence: [{
						required: true,
						message: '请输入合理沉没度',
						trigger: 'blur'
					}]
				},
				labelPosition: 'left',
				border: true,
				
			};
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			submit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						// 计算混合液密度
						const waterContentDecimal = parseFloat(this.model.waterContent) / 100;
						const mixedLiquidDensity = parseFloat(this.model.oilDensity) * (1 - waterContentDecimal) + 
							waterContentDecimal * (parseFloat(this.model.formationWaterDensity) || 1.1);

						// 计算抽油泵泵口压力
						const pumpPressure = parseFloat(this.model.dissolvedGasOilRatio) / 
							((1 / (parseFloat(this.model.fillFactor) - 1)) / (1 - waterContentDecimal) + 
							parseFloat(this.model.gasDissolutionFactor));

						// 计算井筒液柱压力
						const liquidColumnPressure = 0.01 * mixedLiquidDensity * 
							(parseFloat(this.model.midDepth) - parseFloat(this.model.pumpDepth) + 
							parseFloat(this.model.reasonableSubmergence));

						// 计算合理井底流压
						this.model.bottomHolePressure = (pumpPressure + liquidColumnPressure).toFixed(2);
					}
				});
			}
		}
	};
</script>

<style scoped lang="scss">
	.wrap {
		padding: 30rpx;
	}

	.u-config-wrap {
		margin-top: 30rpx;
	}

	.u-config-title {
		padding: 20rpx;
		font-size: 32rpx;
		font-weight: bold;
	}

	.u-config-item {
		padding: 20rpx;
	}

	.u-item-title {
		font-size: 28rpx;
		font-weight: bold;
		margin-bottom: 10rpx;
	}

	.u-item-desc {
		font-size: 24rpx;
		color: #666;
		margin-bottom: 5rpx;
	}
</style>